--[[
    desc: 魂石洗炼概率展示界面
    author:Hoo
    time:2022-01-09 21:59:42
]]

--- @class UIBaptismProbability
local UIBaptismProbability = UIBase.New(PanelResNames.UIBaptismProbability)
local M = UIBaptismProbability

--- 数据集合
local mItemDatas = nil

function M.Init()
    UIBase.Init(M)
end

--- @protected
function M:OnCreate()
    -- 列表
    self.listItem = self:GetChild("Content")
    self:SetDynamicList(self.listItem, self.listItemRenderer, self)

    self:GetChild("bg/title").text = getLanguage("DebrisText3")
    self:RegisterOnClick(self:GetChild("but_back"), self.onClickClose, self)
    self:RegisterOnClick(self:GetChild("bgClose"),  self.onClickClose, self)
end
--- @protected
function M:OnEnable()
    local tableData = dataTable.getDataTable("t_debrisminorskill")

    mItemDatas = {}
    for key, data in pairs(tableData) do
        table.insert(mItemDatas, { value = data.f_Prob / 100, desc = data.f_CommonKey })
    end

    self:initUI()
end
--- @protected
function M:OnDisable()
end
--- @protected
function M:OnDestroy()
    mItemDatas = nil
end

--- 初始化UI
function M:initUI()
    self.listItem.numItems  = #mItemDatas
end

--- 列表item
--- @private
--- @param index number  索引
--- @param obj   GObject 属性item对象
function M:listItemRenderer(index, obj)
    local data = mItemDatas[index]
    local txtRate = obj:GetChild("Text_Probability")
    local txtDesc = obj:GetChild("Text_SkillDesc")
    txtRate.text = data.value .. "%"
    txtDesc.text = getLanguage(data.desc)
end

--- 关闭界面
--- @private
function M:onClickClose()
    closeUI(PanelResNames.UIBaptismProbability)
end

return M
